#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# modified for node_package by dizzyd@basho.com and jared@basho.com

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

ROOTDIR := debian/riak

## Clear variables that may confound our build of sub-projects; also
## note that it is necessary to use overlay_vars relative to .. as
## the generate command EXECUTES in rel/
build:
	unset CC CFLAGS CPPFLAGS LDFLAGS CXX CXXFLAGS \
		&& make rel-deb
	touch build

clean:
	dh_clean
	rm -f build
	make clean

## dh_shlibdeps was added to figure out the dependencies on shared libraries
##   and will populate the ${shlibs:Depends} callout in the control file
install: LIBDIR := $(ROOTDIR)/usr/lib/riak
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install
	dh_installman
	dh_installinit --name=riak --no-start
	dh_fixperms
	chmod 0755 $(ROOTDIR)/etc/riak
	chmod -R a+rX $(ROOTDIR)/etc/riak
	for file in lib/env.sh lib/app_epath.sh erts-*/bin/nodetool; do \
		if [ -f $(LIBDIR)/$$file ]; then \
			chmod 0755 $(LIBDIR)/$$file; \
		fi; \
	done
	chmod -R go+rX debian/riak/usr/lib/riak/lib/
	dh_shlibdeps

# We have nothing to do by default.
binary-indep: install build-stamp
build-stamp:

# Build architecture-dependent files here.
binary-arch: install
	dh_strip -a
	dh_compress -a
	dh_installdeb
	dh_gencontrol
	dh_builddeb

binary: binary-indep binary-arch
